﻿
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using Model;


namespace MsDAL
{
    public partial class Pot3b00DAL : Pot3b00Base
    {
        /// <summary>
        /// 备份商品资料
        /// </summary>
        /// <param name="usercode">用户编码</param>
        /// <param name="listid">商品表主键</param>
        /// <param name="isBeforeValue">是否为原值</param>
        /// <returns></returns>
        public SqlApp Bak(string usercode, string listid, bool isBeforeValue,string loginUser)
        {
            Sys0a60DAL dal = new Sys0a60DAL();

            string sql = @" INSERT INTO Pot3b00
        (pamt, calcode, bprice, price, pbrand, um, [level], status, 
        pclass, propty, ptype, barcode, pid, productname, productcode, changetype, 
        changedate, usercode, listid)
        SELECT pamt, calcode, bprice, price,brand as pbrand,ulistid as um, leverid as level,
        status, pvlistid as pclass, ptlistid as propty, ptype ,
        barcode, listid as pid, productname, productcode, @changetype as changetype, 
        GETDATE() as changedate, @usercode as usercode, @newId as listid
        FROM Pot3a00 a WHERE listid = @listid ";

            SqlParameter[] parameters = {
				new SqlParameter("@changetype",SqlDbType.NVarChar),
                new SqlParameter("@usercode",SqlDbType.NVarChar),
                new SqlParameter("@newId",SqlDbType.NVarChar),
                new SqlParameter("@listid",SqlDbType.NVarChar)
				};

            parameters[0].Value = isBeforeValue ? "Y" : "N";
            parameters[1].Value = usercode;
            parameters[2].Value = dal.CreateSn("pot3b00_listid", loginUser);
            parameters[3].Value = listid;

            return new SqlApp(sql, new ArrayList(parameters), false, "回写商品的历史记录失败！");
        }
    }
}
